package alertScene

import (
	"context"
	"devops-super/api/alerts/v1"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.AlertSceneGetPageLstReq) (res *v1.AlertSceneGetPageLstRes, err error) {
	res, err = service.AlertScene().GetPageLst(ctx, req)
	return
}

func (*ControllerV1) Add(ctx context.Context, req *v1.AlertSceneAddReq) (res *v1.AlertSceneAddRes, err error) {
	alertScene := req.ToEntity()
	alertScene.CreatedAt = gtime.Now()
	alertScene.UpdatedAt = gtime.Now()
	err = service.AlertScene().Add(ctx, alertScene)
	return
}

func (*ControllerV1) Upt(ctx context.Context, req *v1.AlertSceneUptReq) (res *v1.AlertSceneUptRes, err error) {
	alertScene := req.ToEntity()
	alertScene.Id = req.Id
	alertScene.UpdatedAt = gtime.Now()
	err = service.AlertScene().Upt(ctx, alertScene)
	return
}

func (*ControllerV1) UptStatus(ctx context.Context, req *v1.AlertSceneUptStatusReq) (res *v1.AlertSceneUptStatusRes, err error) {
	err = service.AlertScene().UptStatus(ctx, req.Id, req.Status)
	return
}

func (*ControllerV1) Del(ctx context.Context, req *v1.AlertSceneDelReq) (res *v1.AlertSceneDelRes, err error) {
	err = service.AlertScene().Del(ctx, req.Id)
	return
}

func (*ControllerV1) GetOne(ctx context.Context, req *v1.AlertSceneGetOneReq) (res *v1.AlertSceneGetOneRes, err error) {
	res1, err := service.AlertScene().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.AlertSceneGetOneRes)
	res.Info = res1
	return
}

func (*ControllerV1) GetOptions(ctx context.Context, req *v1.AlertSceneGetOptionsReq) (res *v1.AlertSceneGetOptionsRes, err error) {
	res, err = service.AlertScene().GetOptions(ctx, req)
	return
}
